﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Sto6a00DAL : Sto6a00Base
    {
        public override SqlApp Add(Sto6a00 sto6a00)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Sto6a00(");
            strSql.Append("pid ,storageid ,storageqty ,listid )");
            strSql.Append(" select ");
            strSql.Append("@pid ,@storageid ,@storageqty ,@listid ");
            strSql.Append(" where not exists(select 1 from Sto6a00 a where a.storageid = @storageid and pid = @pid) ");

            SqlParameter[] parameters = {
				new SqlParameter("@pid",SqlDbType.NVarChar),
				new SqlParameter("@storageid",SqlDbType.NVarChar),
				new SqlParameter("@storageqty",SqlDbType.Decimal),
				new SqlParameter("@listid",SqlDbType.NVarChar)
				};
            parameters[0].Value = sto6a00.Pid;
            parameters[1].Value = sto6a00.Storageid;
            parameters[2].Value = sto6a00.Storageqty;
            parameters[3].Value = sto6a00.Listid;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "在您操作的时候，可能库存已经发生改变了，请重新操作！");
        }

        public override SqlApp Update(Sto6a00 sto6a00)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Sto6a00 set ");
            strSql.Append("pid=@pid ,storageid=@storageid ,storageqty=@storageqty ");
            strSql.Append("where listid=@listid and storageqty=@oldstorageqty");
            SqlParameter[] parameters = {
				new SqlParameter("@pid", SqlDbType.NVarChar),
				new SqlParameter("@storageid", SqlDbType.NVarChar),
				new SqlParameter("@storageqty", SqlDbType.Decimal),
				new SqlParameter("@oldstorageqty", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = sto6a00.Pid;
            parameters[1].Value = sto6a00.Storageid;
            parameters[2].Value = sto6a00.Storageqty;
            parameters[3].Value = sto6a00.OldStorageQty;
            parameters[4].Value = sto6a00.Listid;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "在您操作的时候，可能库存已经发生改变了，请重新操作！");		
        }
    }
}
